layui.use(['form', 'element', 'layer'], function () {
    let form = layui.form;
    let element = layui.element;
    let layer = layui.layer;
});

layui.use(['form', 'layer'], function () {
    let form = layui.form;
    let layer = layui.layer;
});

$(document).ready(function () {


    $(".del_btn").click(function () {

        let bookId = $(this).val();
        console.log('book', bookId)

        //页面层
        layer.open({
            type: 1 //Page层类型
            , skin: 'layui-layer-molv'
            , area: ['380px', '270px']
            , title: ['续期', 'font-size:18px']
            , btn: ['确认', '取消']
            , shadeClose: true
            , shade: 0 //遮罩透明度
            , content: $("#window")
            , yes: function () {
                addTimeBook(bookId);
            }
        });


    });
});

//续期
function addTimeBook(bookId) {
    let data = $('#updateForm').serialize();
    console.log(data.substring(9, 19))

    $.ajax({
        async: false,
        type: "post",
        url: "/updateBooks",
        dataType: "json",
        data: {bookId: bookId, date: data.substring(9, 19)},
        success: function (data) {
            console.log(data.toString());
            if (data.toString() == "true") {
                layer.msg('续期成功!', {icon: 6, time: 2000});
                setTimeout(function () {
                    location.reload();
                }, 1500)
            } else {
                layer.msg('续期失败!', {icon: 7, time: 2000});
            }
        },
        error: function (data) {
            layer.alert(data.result);
        }
    });
};